<div class="alert alert-danger-light">
    <p><i class="fa fa-info"></i> {:__('请谨慎操作此功能')}</p>
</div>
<style>
    .form-group .col-sm-2{
        min-width: 120px;
    }

</style>
<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
    <div class="">
		<div class="panel panel-success">
                <div class="panel-heading">
                    <h4 class="panel-title">
                        <a data-toggle="collapse"
                           href="#collapseOne">
                            <span>{:__('基本信息')}</span> 
                        </a>
                       
                    </h4>
                </div>
                <div id="collapseOne" class="panel-collapse collapse in">
                    <div class="panel-body">
						<div class="col-md-4 col-xs-12 form-group">
							<label for="c-number" class="control-label col-xs-12 col-sm-2">{:__('合同编号')}:</label>
							<div class="col-xs-12 col-sm-8">
								<input id="c-number" data-rule="required" type="text" class="form-control" name="row[number]" value="{$row.number}"   />
							</div>
						</div>
						<div class="col-md-4 col-xs-12 form-group">
							<label for="c-name" class="control-label col-xs-12 col-sm-2">{:__('合同名称')}:</label>
							<div class="col-xs-12 col-sm-8">
								<input id="c-name" data-rule="required" type="text" class="form-control" name="row[name]" value="{$row.name}"  />
							</div>
						</div>

						<div class="col-md-4 col-xs-12 form-group">
							<label for="c-customer_id" class="control-label col-xs-12 col-sm-2">{:__('选择客户')}:</label>
							<div class="col-xs-12 col-sm-8">
								<input id="c-customer_id" data-rule="required" data-source="facrm/customer/index/selectpage/type/all"
									   class="form-control selectpage"  type="text" value="{$row.customer_id}" disabled>

							</div>
						</div>
						<div class="col-md-4 col-xs-12 form-group business_id_div" >
							<label for="c-business_id" class="control-label col-xs-12 col-sm-2">{:__('选择商机')}:</label>
							<div class="col-xs-12 col-sm-8">


								<input id="c-business_id" data-rule="required" data-source="facrm/business/index/index"
									   class="form-control selectpage" name="" type="text" value="{$row.business_id}"  disabled>

							</div>
						</div>

						<div class="col-md-4 col-xs-12 form-group">
							<label for="c-money" class="control-label col-xs-12 col-sm-2">{:__('合同金额')}:</label>
							<div class="col-xs-12 col-sm-8">
								<input id="c-money" type="number"  class="form-control" name="row[money]" value="{$row.money}"   />
							</div>
						</div>
						<div class="col-md-4 col-xs-12 form-group">
							<label for="c-order_time" class="control-label col-xs-12 col-sm-2">{:__('下单时间')}:</label>
							<div class="col-xs-12 col-sm-8">
								<input id="c-order_time"  value="{:datetime($row.order_time)}"  class="form-control datetimepicker" data-date-format="YYYY-MM-DD" data-use-current="true" name="row[order_time]" type="text" >
							</div>
						</div>
						<div class="col-md-4 col-xs-12 form-group">
							<label for="c-start_time" class="control-label col-xs-12 col-sm-2">{:__('合同开始时间')}:</label>
							<div class="col-xs-12 col-sm-8">
								<input id="c-start_time"  value="{:datetime($row.start_time)}"  class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm" data-use-current="true" name="row[start_time]" type="text"  >
							</div>
						</div>
						<div class="col-md-4 col-xs-12 form-group">
							<label for="c-end_time" class="control-label col-xs-12 col-sm-2">{:__('合同结束时间')}:</label>
							<div class="col-xs-12 col-sm-8">
								<input id="c-end_time"  value="{:datetime($row.end_time)}"  class="form-control datetimepicker" data-date-format="YYYY-MM-DD HH:mm" data-use-current="true" name="row[end_time]" type="text"  >
							</div>
						</div>


						<div class="col-md-4 col-xs-12 form-group">
							<label for="c-contacts_id" class="control-label col-xs-12 col-sm-2">{:__('客户签约人')}:</label>
							<div class="col-xs-12 col-sm-8">
								<input id="c-contacts_id" data-source="facrm/contract/index/selectcontact"
									   class="form-control selectpage" name="row[contacts_id]" type="text" value="{$row.contacts_id}"  >

							</div>
						</div>

						<div class="col-md-4 col-xs-12 form-group">
							<label for="c-order_admin_id" class="control-label col-xs-12 col-sm-2">{:__('公司签约人')}:</label>
							<div class="col-xs-12 col-sm-8">
								<input id="c-order_admin_id" data-rule="required" data-source="facrm/common/selectpage/model/admin/type/all" data-field="nickname"
									   class="form-control selectpage" name="row[order_admin_id]" type="text" value="{$row.order_admin_id}"   >

							</div>
						</div>


						<div class="col-md-4 col-xs-12 form-group">
							<label for="c-order_admin_id" class="control-label col-xs-12 col-sm-2">{:__('合同负责人')}:</label>
							<div class="col-xs-12 col-sm-8">
								<input id="c-owner_user_id" data-rule="required" data-source="facrm/common/selectpage/model/admin" data-field="nickname"
									   class="form-control selectpage" name="row[owner_user_id]" type="text" value="{$row.owner_user_id}"   >

							</div>
						</div>

						<div class="col-md-4 col-xs-12 form-group">
							<label for="c-remark" class="control-label col-xs-12 col-sm-2">{:__('备注')}:</label>
							<div class="col-xs-12 col-sm-8">
								<textarea id="c-remark" class="form-control" name="row[remark]">{$row.remark}</textarea>
							</div>
						</div>
					
					</div>
                </div>
            </div>
		
		
		<div class="panel-group" id="accordion">
			 <div class="panel panel-info">
                <div class="panel-heading">
                    <h4 class="panel-title">
                        <a data-toggle="collapse"
                           href="#collapseThree">
                           合同扩展
                        </a>
                    </h4>
                </div>
                <div id="collapseThree" class="panel-collapse collapse in">
                    <div class="panel-body">
                        <div id="extend"></div>

                    </div>
                </div>
            </div>
		
		</div>
        
    </div>

    <div class="row">
        <div class="table-responsive" style="margin: 20px">
            <table id="table" class="table table-striped table-bordered table-hover table-nowrap">
                <thead>
                <th>{:__('序号')}</th>
                <th>{:__('编码')}</th>
                <th style="width: 100px">{:__('商品')}</th>
                <th>{:__('规格')}</th>
                <th>{:__('属性')}</th>
                <th >{:__('单位')}</th>
                <th style="width: 80px">{:__('数量')}</th>
                <th style="width: 80px">{:__('单价')}</th>
                <th>{:__('小计')}</th>
                <th>{:__('备注')}</th>
                <th>{:__('操作')}</th>
                </thead>
                <tbody>
                {php}
                $totalnums=0;
                $allMoney=0;//产品金额小计

                {/php}
                {foreach name="product_list" item="vo"  index="i" }
                {php}
                $totalnums +=$vo['nums'];
                $allMoney+=$vo['subtotal'];
                {/php}
                <tr>
                    <td>{$i}</td>
                    <td>{$vo.info.sku}</td>
                    <td>
                        <input date-rule="required;" style="width: 100px" value="{$vo.info.name}"  type="text" name="product[{$i}][name]" data-index="{$i}" class="find" class="" data-toggle="modal" data-target="#modelProduct"  >
                        <input   type="hidden" name="product[{$i}][product_id]" value="{$vo.product_id}"  >
                        <input   type="hidden" name="product[{$i}][sku]" value="{$vo.sku}" >
                        <input   type="hidden" name="product[{$i}][specification]" value="{$vo.specification}" >
                        <input   type="hidden" name="product[{$i}][prop]" value="{$vo.prop}"  >
                        <input   type="hidden" name="product[{$i}][unit]" value="{$vo.unit}" >
                    </td>
                    <td class="gg">{$vo.specification}</td>
                    <td>
                        {$vo.prop}
                    </td>
                    <td class="unit">{$vo.unit}</td>
                    <td>
                        <input  type="number" value="{$vo.nums}" style="width: 80px" name="product[{$i}][nums]" data-rule="required;integer;range(0~);"  class="nums" onblur="totalNums(this)" >
                    </td>
                    <td><input value="{$vo.price}" type="number" style="width: 80px" data-rule="required;range(0~);" onblur="calMoney(this)" class="unit-price" name="product[{$i}][price]" readonly>
                        <input   type="hidden" name="product[{$i}][subtotal]"  value="{$vo.subtotal}" >
                    </td>
                    <td class="subtotal">
                        {$vo.subtotal}
                    </td>
                    <td> <textarea rows="2" class="remarks" name="product[{$i}][remarks]" cols="20" >{$vo.remarks}</textarea></td>
                    <td>
                        <button type="button" class="btn btn-primary" onclick="addRow()">{:__('添加')}</button>
                        <button type="button" class="btn btn-default" onclick="delRow(this)">{:__('删除')}</button>
                    </td>
                </tr>
                {/foreach}
                <tr>
                    <td>{:__('合计')}</td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td class="totalnums" >{$totalnums}</td>
                    <td></td>
                    <td id="allMoney">{$allMoney}</td>
                    <td></td>
                    <td></td>
                </tr>
                </tbody>
            </table>
        </div>
        <div>

            <div class="row">
                <div class="col-md-7 col-xs-12">
                </div>
                <div class="col-md-2 col-xs-12">
                    <label class="control-label col-xs-12 col-sm-6">{:__('优惠率%')}:</label>
                    <div class="col-xs-12 col-sm-6">
                        <input id="c-rate"  class="form-control"  data-rule="required;float;range(0~100);"  name="row[discount_rate]" type="number" value="{$row.discount_rate}" onblur="calTotalMoneys()">

                    </div>
                </div>
                <div class="col-md-2 col-xs-12">

                    <label class="control-label col-xs-12 col-sm-6"> {:__('产品总额 $')}:</label>
                    <div class="col-xs-12 col-sm-6">
                        <input id="totalMoneys" class="form-control"  name="row[total_price]"  type="number" value="{$row.total_price}">
                        <input id="money" style="display: none;"   readonly="readonly"  type="number" >
                        <input id="allNums" style="display: none;" name="row[totalNums]"  readonly="readonly"  type="number" >
                    </div>

                </div>
            </div>
        </div>
    </div>

    <div class="form-group layer-footer">
        <label class="control-label col-xs-12 col-sm-2"></label>
        <div class="col-xs-12 col-sm-8">
            <button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
            <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
        </div>
    </div>
</form>


<!-- Modal -->
<div class="modal fade" id="modelProduct" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content" style="padding: 15px;">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">{:__('选择产品')}</h4>
            </div>
            <div class="modal-body">
                <div id="lays-row" class="row" >
                    <table id="table2" class="table table-striped table-bordered table-hover " data-show-export="false" data-show-toggle="false" data-show-columns="false">
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    var contract_id={:input('ids')};
</script>



